package com.qiedan.controller.mdy;

import com.qiedan.bean.Car;
import com.qiedan.service.CarService;
import com.qiedan.utils.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;

@RequestMapping("/shopCart")
@RestController
@Slf4j
public class ShopCartController {

    @Autowired
    CarService carService;

    /**
     * 根据用户id查询用户购物车商品信息
     * @return
     */
    @RequestMapping("/list")
    public R<Object> showShopCarList(Integer uid){

        log.info("uid: " + uid);

        return carService.getShopCarListByUserId(uid);
    }

    /**
     * 根据用户id查询用户购物车商品信息
     * @return
     */
    @RequestMapping("/pay")
    public R<Object> payAlone(@RequestBody Car car){

        log.info("car: " + car);

        return carService.payAlone(car);
    }
    /**
     *
     * @return
     */
    @RequestMapping("/add")
    public R<Object> add(@RequestBody Car car){

        log.info("car: " + car);

        return carService.add(car);
    }
    @RequestMapping("/delete")
    public R<Object> delete(Integer cid){

        log.info("cid: " + cid);

        return carService.delete(cid);
    }


    @RequestMapping("/clearShopCart")
    public R<Object> clearShopCart(@RequestBody ArrayList<Car> carList){

        log.info("carList: " + carList);

        return carService.clearShopCart(carList);
    }
}
